#ifndef SQLFDOCOMMON_H
#define SQLFDOCOMMON_H

#include "../../../kegui_global.h"

#include "sqlite3_stmt_free_ptr.h"
#include <QString>
#include <geos.h>

#include <sqlite3.h>

KEGUI_EXPORT int KeSQLiteCount(sqlite3 *db,const QString &sql)
{
    int result = SQLITE_OK;

    sqlite3_stmt* stmt = 0;
    const char* errmsg = 0;
    QByteArray qbs =  sql.toUtf8();
    const char * lpStr = qbs.data();
    result = sqlite3_prepare_v2(db, lpStr, -1, &stmt, &errmsg);
    if(SQLITE_OK == result)
    {
        std::unique_ptr<sqlite3_stmt,struct KeSqliteStmtFreeHandler> stmtPtr(stmt);

        if(SQLITE_ROW == sqlite3_step(stmt))
        {
            int typeField = sqlite3_column_type(stmt, 0);
            if(SQLITE_INTEGER == typeField)
            {
                int val  =  sqlite3_column_int(stmt, 0);
                return val;
            }
        }
    }
    return 0;
}

#endif // SQLFDOCOMMON_H
